<template>
  <el-card class="attend-tabel">
    <el-table :data="tableData" style="width: 100%">
      <el-table-column prop="time" label="考勤日期" width="180">
      </el-table-column>
      <el-table-column prop="cource" label="课程（空内容代表放假）" width="300">
      </el-table-column>
      <el-table-column prop="morningAttendance" label="上午出勤" width="120">
      </el-table-column>
      <el-table-column prop="afterAttendance" label="下午出勤" width="120">
      </el-table-column>
      <el-table-column prop="nightAttendance" label="晚自习出勤" width="120">
      </el-table-column>
      <el-table-column prop="auditStatus" label="申请处理状态" width="300">
      </el-table-column>
      <el-table-column label="备注" width="210">
        <el-popover
          placement="bottom"
          title="备注信息"
          width="400"
          trigger="hover"
        >
          <el-table style="width: 100%" :data="tableData">
            <el-table-column prop="time" label="日期" width="100">
            </el-table-column>
            <el-table-column prop="remarkType" label="备注类型" width="100">
            </el-table-column>
            <el-table-column prop="remark" label="备注信息" width="200">
            </el-table-column>
          </el-table>

          <el-button slot="reference" type="text" size="small">查看</el-button>
        </el-popover>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="{ row }">
          <el-button type="text" size="small" @click="complement(row)"
            >补签</el-button
          >
          <el-button type="text" size="small" @click="apply(row)"
            >请假</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <el-dialog
      :visible="showDialog"
      title="补签"
      width="600px"
      @close="cancelBtn"
    >
      <!-- 作息时间表 -->

      <div class="time-tabel">
        <div class="complement-img">
          <span>作息时间表</span>
        </div>
        <p>上午:08:00-12:00</p>
        <p>下午 14:00-17:00</p>
        <p>晚上 18:00-21:30</p>
      </div>
      <el-form label-position="top" label-width="80px">
        <el-form-item label="补签卡点">
          <el-select placeholder="请选择" v-model="value" style="width: 100%">
            <el-option label="上午" value="上午[待审核]"></el-option>
            <el-option label="下午" value="下午[待审核]"></el-option>
            <el-option label="晚上" value="晚上[待审核]"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="补签说明">
          <el-input
            type="textarea"
            placeholder="请输入30字以内的补签说明"
            v-model="textrea"
            maxlength="30"
            show-word-limit
          ></el-input>
        </el-form-item>
      </el-form>
      <el-row type="flex" justify="center">
        <el-col :span="6">
          <el-button type="primary" size="small" @click="confirmBtn"
            >提交</el-button
          >
          <el-button size="small" @click="cancelBtn">取消</el-button>
        </el-col>
      </el-row>
    </el-dialog>
    <el-dialog :visible="showDialogs" @close="cancelsBtn" title="请假" width="600px">
      <el-form ref="form" label-width="80px" :model="applyData" :rules="applyRules"  style="margin-top: -20px">
        <el-form-item prop="startDate" label="开始时间">
          <el-col :span="11">
            <el-date-picker
              type="date"
              v-model="applyData.startDate"
              placeholder="选择日期"
              style="width: 100%"
            ></el-date-picker>
          </el-col>
          <el-col class="line" :span="2">-</el-col>
          <el-col :span="11">
            <el-select placeholder="请选择时间" v-model="value1">
              <el-option v-for="(item,index) in startValue" :key="index" :label="item.label" :value="item.value"></el-option>

            </el-select>
          </el-col>
        </el-form-item>
        <el-form-item label="结束时间" prop="endDate">
          <el-col :span="11">
            <el-date-picker
              type="date"
              placeholder="选择日期"
              v-model="applyData.endDate"
              style="width: 100%"
            ></el-date-picker>
          </el-col>
          <el-col class="line" :span="2">-</el-col>
          <el-col :span="11">
              <el-select placeholder="请选择时间" v-model="value">
              <el-option v-for="(item,index) in endValue" :key="index" :label="item.label" :value="item.value"></el-option>

            </el-select>
          </el-col>
        </el-form-item>
        <el-form-item prop="timeout" label="请假时长">
          <el-input v-model="applyData.timeout"></el-input>
        </el-form-item>
        <el-form-item prop="applyInformance" label="请假原因">
          <el-select placeholder="请选择请假原因" v-model="applyData.applyInformance">
            <el-option label="事假" value="事假"></el-option>
            <el-option label="病假" value="病假"></el-option>
            <el-option label="面试" value="面试"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item prop="textreas" label="请假说明">
          <el-input
            type="textarea"
            placeholder="请输入30字以内的补签说明"
            v-model="applyData.textreas"
            maxlength="50"
            show-word-limit
          ></el-input>
        </el-form-item>

        <el-form-item>

              <el-button size="small" @click="cancelsBtn">取消</el-button>
              <el-button size="small" type="primary" @click="inputBtn">提交</el-button>

        </el-form-item>
      </el-form>
    </el-dialog>
  </el-card>
</template>

<script>
import { putAttendance } from '@/api/attendance'
export default {
  props: {
    tableData: {
      type: Array,
      default: () => []
    }
  },
  data () {
    return {
      applyForm: {},
      showDialog: false,
      value: '',
      value1: '',
      textrea: '',
      attendId: '',
      formData: {},
      showDialogs: false,
      startValue: [
        {
          label: '上午',
          value: '上午'
        },
        {
          label: '下午',
          value: '下午'
        },
        {
          label: '晚上',
          value: '晚上'
        }
      ],
      endValue: [
        {
          label: '上午',
          value: '上午'
        },
        {
          label: '下午',
          value: '下午'
        },
        {
          label: '晚上',
          value: '晚上'
        }
      ],
      applyData: {
        textreas: '',
        startDate: '',
        endDate: '',
        timeout: '',
        applyInformance: '',
        value: this.value,
        value1: this.value1

      },
      applyRules: {
        applyInformance: [{ required: true, message: '不能为空', trigger: 'blur' }],
        textreas: [{ required: true, message: '不能为空', trigger: 'blur' }, {
          min: 0, max: 50, trigger: 'blur'
        }]
      }

    }
  },
  methods: {
    complement (row) {
      this.showDialog = true
      this.formData = row
    },
    async confirmBtn () {
      console.log(this.attendId)
      console.log(this.value)
      console.log(this.textrea)
      await putAttendance({
        ...this.formData,
        auditStatus: this.value,
        remark: this.textrea
      })
      this.value = ''
      this.textrea = ''

      this.showDialog = false
      this.$message.success('操作成功')
      this.$emit('resetAttendance')
    },
    cancelBtn () {
      this.showDialog = false
    },
    apply (row) {
      this.showDialogs = true
      this.applyForm = row
    },
    inputBtn () {
      this.$refs.form.validate(async isOk => {
        if (isOk) {
          await putAttendance({
            ...this.applyForm,
            ...this.applyData,
            remarkType: this.applyData.applyInformance
          })
          console.log(11)
          this.showDialogs = false
          this.$message.success('提交成功')
          this.$emit('resetAttendance')
        } else {
          this.$message.error('校验不通过')
        }
      })
    },
    cancelsBtn () {
      this.applyData = {
        textreas: '',
        date: '',
        timeout: '',
        applyInformance: '',
        value: '',
        id: ''
      }
      this.showDialogs = false
    }
  }
}
</script>

<style scoped lang="less">
.attend-tabel {
  margin-top: 10px;
  /deep/ .el-dialog {
    .el-dialog__header {
      background-color: rgb(102, 168, 255);
    }
    .el-dialog__title {
      color: #fff;
    }
    .el-dialog__close {
      color: #fff;
    }
    .time-tabel {
      .complement-img {
        width: 165px;
        height: 32px;
        background: url("~@/assets/images/矩形背景.png") center center;
        line-height: 32px;
        text-align: center;
        margin-left: 200px;
        font-size: 16px;
        color: #2477fc;
      }
    }
    .el-form {
      margin-top: 30px;
    }
  }
}
</style>
